{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Comparing two 1D discrete distributions. Example\n",
    "\n",
    "We would like to know which distribution d1 or d2 is closer to distribution u.\n",
    "The correct answer here should be that distribution d1 is closer to u, because it covers the same area the u covers, whereas d2 only exists in the middle of the u (explanation in very simple English :))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAFJpJREFUeJzt3X+wnmV95/H3p/lhRKxQyDpdQki0EUlhJ+BpcNeR7lTAuOyA7OgQf3Rwx07sjhG7jrODyw6y6TD+qNP1H1plShymraaIMHNgUynrj647XSRBEAg0a4gUTrGSBlbdlQQC3/3juXEfDyec5yRP7kO83q+ZM7l/XPf9vZ5zcj7nPtdz39dJVSFJasMvzXcHJEn9MfQlqSGGviQ1xNCXpIYY+pLUEENfkhpi6EtSQwx9SWqIoS9JDVk43x2Y7sQTT6wVK1bMdzck6ahy1113/WNVLZ2t3Usu9FesWMH27dvnuxuSdFRJ8nejtHN4R5IaYuhLUkMMfUlqyEtuTF+SjrRnnnmGqakp9u3bN99dmbMlS5awbNkyFi1adEjHG/qSmjM1NcUrX/lKVqxYQZL57s7Iqoq9e/cyNTXFypUrD+kcIw3vJFmXZGeSXUkun2H/7ya5L8k9Sf5HktVD+z7WHbczyVsPqZeSNEb79u3jhBNOOKoCHyAJJ5xwwmH9hjJr6CdZAFwDvA1YDbxrONQ7X6yqM6pqDfBp4A+7Y1cD64FfB9YBf9SdT5Lm1dEW+M873H6PcqW/FthVVbur6mlgC3DRcIOq+vHQ6iuA5/8G40XAlq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kJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x110d603d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# small value\n",
    "sm = 1e-09\n",
    "d1 = np.repeat(sm, 10)\n",
    "d1[[0,4,8]]= 0.3\n",
    "d2 = np.repeat(sm, 10)\n",
    "d2[[4,5,6]] = 0.3\n",
    "\n",
    "u = np.repeat(0.1, 10)\n",
    "\n",
    "## plotting\n",
    "ind = np.arange(10)\n",
    "w = 0.2\n",
    "d1_plot = plt.bar(ind - w, d1, width = w, align='center')\n",
    "d2_plot = plt.bar(ind, d2, width= w, align='center')\n",
    "u_plot = plt.bar(ind + w, u, width= w, align='center')\n",
    "plt.legend( (d1_plot[0], d2_plot[0], u_plot[0]), ('d1', 'd2', 'u') )\n",
    "\n",
    "objects = list(map(str, range(10)));\n",
    "plt.xticks(ind, objects);\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Kullback-Leibler divergence\n",
    "\n",
    "Compares two distribution. Non commutative, thus not a metric.\n",
    "The smaller the value is the more similar two distribution are.\n",
    "\n",
    "$$ D_{KL}(p || q) = \\sum_{i=0}^N p(x_i) \\mathrm{log}\\frac{p(x_i)}{q(x_i)} $$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "def KLDivergence(p,q):\n",
    "    logTerm = np.log2(np.divide(p,q))\n",
    "    d = np.sum(np.multiply(p,logTerm))\n",
    "    return d"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before the KL divergence could be applied to the discreet distributions, they should be convolved with gaussian kernel. They should be made more smooth.Formally the process is called **Kernel density estimation**. Otherwise in the given example the value of the divergence is the same for <d1,u> and <d2,u>, since they have the same number of bins of the same height. However, since the location of the bins are not the same, the smoothed version will populate the difference nearby bins. I am more than sure that there is a sane mathematical explanation behind this smoothness action, but I don't know it yet :)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Convolving with gaussian\n",
    "you need to create a Gaussian that's discretized at the same spatial scale as your curve, then just convolve.\n",
    "Specifically, say your original curve has N points that are uniformly spaced along the x-axis\n",
    "Then the point spacing along the x-axis will be (physical range)/(digital range) = (10 -0)/N\n",
    "\n",
    "**Side note**: Convolving a probability distribution with a normalized kernel leads to a probability distribution. (Simple english) If your value sum up to 1 and convolve them with a kernel (sum of elements of which sum to 1), you will automatically get a probability distribution (all values sum to 1)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJztnXuUXFd1p79d1d16v7sly3q1LCRjydgYhMHY4AcQ7IHYQCCxs0KAIfEMgwMJzEpMMsNkkZAHkxAgy8nCJCTOBGI8Dg4KMZiJ7YDfSDYWtmQkS63uVltv9UPvVlfVnj9O3e7q7nrcqrqvqtrfWlqlqrp17qnedfbZd5/f3UdUFcMwDKO5SMXdAcMwDCN4zLkbhmE0IebcDcMwmhBz7oZhGE2IOXfDMIwmxJy7YRhGE2LO3TAMowkx524YhtGEmHM3DMNoQtriOnFnZ6d2d3fHdXrDMIyG5Nlnnz2mql2VjovNuXd3d7Nt27a4Tm8YhtGQiEifn+MsLWMYhtGEmHM3DMNoQsy5G4ZhNCHm3A3DMJoQc+6GYRhNiC/nLiI3isguEdkjIncWef/DInJURJ7P//u14LtqGIZh+KWiFFJE0sBdwDuAAWCriGxR1Z1TDv2Wqt4RQh8NwzCMKvETuV8J7FHVHlU9D9wL3B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HoAESkG7gCeCbenkTGl4DfhpbZBPQi4Cjwd/lU1N+IyJy4OxU2qvoK8GdAP3AQGFHVH8Tbq0hZpqoHwQVzwNIgGm005+5rI+5mRETmAv8M/Kaqnoi7P2EjIu8Gjqjqs3H3JULagNcBf62qVwCnCegSPcnkc8y3AGuBC4E5IvIr8faq8Wk05z4ArCp4vpImvXwrRETacY79G6r67bj7ExFXAzeLSC8u/XaDiPxjvF0KnQFgQFW9K7P7cc6+2Xk7sE9Vj6rqGPBt4M0x9ylKDovIcoD845EgGm005+5ns+6mQkQEl4N9SVW/GHd/okJVP6OqK1W1G2fnR1S1qaM5VT0E7BeRi/MvvQ3YGWOXoqIfeJOIzM7/3t9GCywkF7AF+FD+/x8CvhNEo772UE0KpTbrjrlbYXM18EHgBRF5Pv/a7+b3tTWaj98AvpEPXnqAj8Tcn9BR1WdE5H7gOZw67Cc06d2qIvJPwHVAp4gMAP8L+BPgPhH5KG6iC2Q/artD1TAMowlptLSMYRiG4QNz7oZhGE2IOXfDMIwmxJy7YRhGE2LO3TAMowkx524YhtGEmHM3DMNoQsy5G4ZhNCH/H65x95OS1iZ7AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10d3ed510>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def convolve1D(y, sigma, discr):\n",
    "    gx = np.arange(-3*sigma, 3*sigma, discr)\n",
    "    gaussian = np.exp(-(gx/sigma)**2/2)\n",
    "    z = np.convolve(y, gaussian, mode=\"same\")\n",
    "    return z\n",
    "\n",
    "x = np.arange(0,10, 0.1)\n",
    "y = np.repeat(sm, x.shape[0])\n",
    "y[[10,50]] = 0.5\n",
    "\n",
    "z = convolve1D(y, 0.5,0.1)\n",
    "\n",
    "plt.plot(x,y)\n",
    "plt.plot(x, z)\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Divergence d1 to u 1.3495510787832004\n",
      "Divergence d2 to u  1.6078272976845267\n"
     ]
    }
   ],
   "source": [
    "sigma = 0.2\n",
    "d1_blurred = convolve1D(d1, sigma, 1)\n",
    "d2_blurred = convolve1D(d2, sigma, 1)\n",
    "\n",
    "\n",
    "#normalize to make it a probability distribution after the convolving\n",
    "d1_blurred = d1_blurred / np.sum(d1_blurred)\n",
    "d2_blurred = d2_blurred / np.sum(d2_blurred)\n",
    "\n",
    "print \"Divergence d1 to u\", KLDivergence(d1_blurred,u)\n",
    "print \"Divergence d2 to u\", KLDivergence(d2_blurred,u)\n",
    "print \"Divergence u to u\", KLDivergence(u,u)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Entropy \n",
    "\n",
    "Found the biggest source of my confusion about entropy.\n",
    "When thinking about entropy the **less information the process \"hides\", the better** because there is less uncertainty about the outcome. If we have a small amount of information, there is nothing there to guess. That is why the fair coin toss has (better hides) the most information since we don't know anything more about what to expect next if we have already seen an outcome. Probably should consider the term information as \"information you don't know\" rather than the one you know.\n",
    "\n",
    "This definition of information is super confusing if you got used to the term \"information\" as the inverse of \"uncertainty\", where the less information you have the more is your uncertainty.\n",
    "\n",
    "### Random process perspective\n",
    "Let's assume there exist a random process (black magic) that produced the distribution we need to work with.\n",
    "By wikipedia definition, entropy is an average amount of information produced by a random process.\n",
    "This means that given a distribution, we can compute the entropy as  $$H = -\\sum_i^n p(x_i)\\mathrm{log(p(x_i))}$$\n",
    "\n",
    "### Data sending perspective\n",
    "Let's assume we need to send some information (string/text) though a channel, so that we need to minimize the amount of sent information (bits).\n",
    "Then we might want to reduce or decrypt the string. And entropy tells us the average amount of bits per letter that are needed to encrypt this string. (Side note: appearently *information theory* will tell how to exactly map those letters to the bits)\n",
    "If all the symbols occur with the same frequence/probability than there is no better way to reduce the string in less bits than there already are in a string (?) If on the other hand, someone (probably the same black magic from above) tells us the more precise probability of the letters, than we would assign less bits to the letters that occur often and more bits for the rare ones and the average bit information is captured as $$H = -\\sum_i^n p(x_i)\\mathrm{log_2(p(x_i))}$$\n",
    "\n",
    "### Other thoughts\n",
    "The bigger the entropy the more unpredictable the states / variables / values in distribution are?\n",
    "The biggest entropy is when every state is the same possible, e.g. uniform distribution. Since then every state needs the same amount of bits to be encoded.\n",
    "The smallest entropy is when the same event occur always/never.\n",
    "\n",
    "**Intuition behing log**: The more probable the event is, the less information it brings. Since if we observe the same event (variable) all the time, it doesn't tell us about other possible outcomes. Thus, the more rare the event is the more information it brings.\n",
    "That's why **-log(x)** function is a good choice, since it is monotonically decreasing for increasing values of probability. \n",
    "Information should also have other 3 properties discribed on wikipedia under Rationale.\n",
    "\n",
    "*Question*: if entropy is an average amount of information per state ($x_i$), why can't we just average the -log(x_i) like  $\\frac{1}{N}\\sum_i^n(-\\mathrm{log}p(x_i))$ ?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## visualization of log just to remind how the log looks like :)\n",
    "prob = np.arange(0.0001, 1.0, 0.01)\n",
    "f = -np.log2(prob)\n",
    "plt.subplot(121)\n",
    "plt.plot(prob, f, 'r-');\n",
    "plt.xlabel('prob');\n",
    "plt.ylabel('log');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Entropy of a distribution 1.5632692440310552\n",
      "Average log information  21.449236676040247\n",
      "Entropy of a uniform distribution 3.321928094887362\n"
     ]
    }
   ],
   "source": [
    "def computeEntropy(dist):\n",
    "    ent = 0\n",
    "    for el in dist:\n",
    "        ent += -el * np.log2(el)\n",
    "    return ent\n",
    "\n",
    "\n",
    "print \"Entropy of a distribution\", computeEntropy(d1)\n",
    "le = 0\n",
    "for el in d1:\n",
    "    le += -np.log2(el)\n",
    "print \"Average log information \", le/d1.shape[0]\n",
    "print \"Entropy of a uniform distribution\", computeEntropy(u)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Connection between KL and Entropy\n",
    "\n",
    "Based on the wikipedia article (https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence) and Kraft-McMillan theorem, we can relate entropy and Kullback-Leibler divergence.\n",
    "$$ D_{KL}(P|| Q) = -\\sum_x{p(x)\\mathrm{log}(q_x)} + \\sum_x{p(x)\\mathrm{log}(p_x)}$$ where the first term is $H(P,Q)$ cross entropy(?) and second term is an entropy $H(P)$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
